﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections;

namespace Kaixin.BLL.Helper
{
    public abstract class RegexHelper
    {
        public static string Match(string html, string regex)
        {
            StringBuilder sb = new StringBuilder();
            foreach (Match matche in Regex.Matches(html, regex))
            {
                sb.Append(matche.Value);
            }
            return sb.ToString();
        }
        [Obsolete]
        public static List<string> MatchToList(string html, string regex)
        {
            List<string> list = new List<string>();
            foreach (Match matche in Regex.Matches(html, regex))
            {
                list.Add(matche.Value);
            }
            return list;
        }
        public static List<DictionaryEntry> MatchToUidAndName(string html, string regex)
        {
            List<DictionaryEntry> list = new List<DictionaryEntry>();
            foreach (Match matche in Regex.Matches(html, regex))
            {
                if (!matche.Groups[2].Value.EndsWith("的首页"))
                {
                    list.Add(new DictionaryEntry() { Key = matche.Groups[1], Value = matche.Groups[2] });
                }
                
            }
            return list;
        }
        public static List<GroupCollection> Matches(string html, string regex)
        {
            return Matches(html,regex,RegexOptions.None);
        }
        public static List<GroupCollection> Matches(string html, string regex,RegexOptions ro)
        {
            List<GroupCollection> list = new List<GroupCollection>();
            foreach (Match item in Regex.Matches(html, regex, ro))
            {
                list.Add(item.Groups);
            }
            return list;
        }

        /// <summary>
        /// 最小2位数的数字
        /// </summary>
        public static string NumberReg { get { return "\\d{2,}"; } }
        /// <summary>
        /// 所有好友超链接
        /// </summary>
        public static string AllFirendAReg { get { return "<a\\s([^<]*) title=\"所有好友\">([^<]*)</a>"; } }
        /// <summary>
        /// 好友超链接带UID与name
        /// </summary>
        public static string FirendAReg { get { return "<a href=\"/home/\\u003Fuid=(\\d{3,})\" class=\"sl\"\\s{0,}>([^<]*)</a>"; } }

        /// <summary>
        /// 好友分页获取最大页码开始的条数
        /// </summary>
        public static string FirendMaxStartReg { get { return "start=(\\d{2,})"; } }
        /// <summary>
        /// 请求好友获得的返回代码
        /// 2已经是好友，3需通过验证，4ok，5你的好友数已超过1000，6问题，7只有她好友的好友才可以给她发送好友请求，8对方已经到上限
        /// </summary>
        public static string AddFirendReturnType { get { return "var type = \"(\\d{1})\";"; } }
    }
}
